package edu.uoc.tdp.client.proves;

import edu.uoc.tdp.beans.conexio.ResponsableEvents;
import edu.uoc.tdp.beans.proves.EstatProva;
import edu.uoc.tdp.beans.proves.Prova;
import edu.uoc.tdp.common.EOlympicsException;
import edu.uoc.tdp.common.EOlympicsUtils;
import edu.uoc.tdp.common.RemotProvesInterface;
import edu.uoc.tdp.common.TDSLanguageUtils;
import java.rmi.RemoteException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;


/**
 * Classe gràfica (Pantalla buscador de proves) <BR>
 * En aquesta pantalla podrem buscar totes les proves del sistema definin uns <br>
 * paràmetres per poder filtrar les diferents proves
 * @author Grup TDP 1X4J
 */


public class PanelBuscadorProves extends javax.swing.JFrame {
    
    private RemotProvesInterface remotProves;
    private ResponsableEvents usuari;
    private List<Prova> proves;
    private Prova provaSeleccionada;
    /**
     * Constructor per defecte
     */
    public PanelBuscadorProves() {
        initComponents();
        pintarEtiquetes();
        TableColumnModel modelColumna = jTaulaProves.getColumnModel(); 
        provaSeleccionada=null;
        modelColumna.getColumn(1).setPreferredWidth(400);
         
    }
    /**
     * Constructor amb dos paràmetres   
     * @param pUsuari           Identificador de l'usuari actual
     * @param pRemotProves      Remot que ens permet connectar amb el servidor
     */
    public PanelBuscadorProves(ResponsableEvents pUsuari,RemotProvesInterface pRemotProves){
        this();        
        this.remotProves=pRemotProves;
        this.usuari=pUsuari;        
    }
    

    /** 
     * Generació automàtica de codi via NETBEANS
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelProva = new javax.swing.JPanel();
        jLProva = new javax.swing.JLabel();
        jTIdProva = new javax.swing.JTextField();
        jTDescripcio = new javax.swing.JTextField();
        jLIdProva = new javax.swing.JLabel();
        jLDescripcio = new javax.swing.JLabel();
        jPanelInscripcio = new javax.swing.JPanel();
        jLDataInscripcio = new javax.swing.JLabel();
        jTIniInscripcio = new javax.swing.JTextField();
        jLdataFiInscripcio = new javax.swing.JLabel();
        jTFiInscripcio = new javax.swing.JTextField();
        jLdataIniInscripcio = new javax.swing.JLabel();
        jLDataRealitzacio = new javax.swing.JLabel();
        jLdataIniRealitzacio = new javax.swing.JLabel();
        jTIniRealitzacio = new javax.swing.JTextField();
        jLDataFiRealitzacio = new javax.swing.JLabel();
        jTFiRealitzacio = new javax.swing.JTextField();
        jPanelBotons = new javax.swing.JPanel();
        jBBuscar = new javax.swing.JButton();
        jBVeure = new javax.swing.JButton();
        jBSortir = new javax.swing.JButton();
        jBNovaProva = new javax.swing.JButton();
        jPanelFiltre = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTaulaProves = new javax.swing.JTable();
        jPanellMenu = new javax.swing.JMenuBar();
        jMenuEdicio = new javax.swing.JMenu();
        jMenuItemSortir = new javax.swing.JMenuItem();
        jMenuArxiu = new javax.swing.JMenu();
        jMenuItemNova = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuItemBuscar = new javax.swing.JMenuItem();
        jMenuItemVeure = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanelProva.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.panelprova")));
        jPanelProva.setName("jPanelProva"); // NOI18N

        jLProva.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLProva.setText("jLProva");
        jLProva.setName("jLProva"); // NOI18N

        jTIdProva.setName("jTIdProva"); // NOI18N

        jTDescripcio.setName("jTDescripcio"); // NOI18N

        jLIdProva.setText("jLabel1");
        jLIdProva.setName("jLIdProva"); // NOI18N

        jLDescripcio.setText("jLabel1");
        jLDescripcio.setName("jLDescripcio"); // NOI18N

        javax.swing.GroupLayout jPanelProvaLayout = new javax.swing.GroupLayout(jPanelProva);
        jPanelProva.setLayout(jPanelProvaLayout);
        jPanelProvaLayout.setHorizontalGroup(
            jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProvaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLProva)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLIdProva, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTIdProva, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTDescripcio, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                    .addComponent(jLDescripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanelProvaLayout.setVerticalGroup(
            jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProvaLayout.createSequentialGroup()
                .addGroup(jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLIdProva)
                    .addComponent(jLDescripcio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addGroup(jPanelProvaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLProva)
                    .addComponent(jTIdProva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTDescripcio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanelInscripcio.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.paneldata")));
        jPanelInscripcio.setEnabled(false);
        jPanelInscripcio.setName("jPanelInscripcio"); // NOI18N

        jLDataInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLDataInscripcio.setText("Data Inici Inscripció");
        jLDataInscripcio.setName("jLDataInscripcio"); // NOI18N

        jTIniInscripcio.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTIniInscripcio.setName("jTIniInscripcio"); // NOI18N

        jLdataFiInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLdataFiInscripcio.setText("Data Inici Inscripció");
        jLdataFiInscripcio.setName("jLdataFiInscripcio"); // NOI18N

        jTFiInscripcio.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTFiInscripcio.setName("jTFiInscripcio"); // NOI18N

        jLdataIniInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLdataIniInscripcio.setText("Data Inici Inscripció");
        jLdataIniInscripcio.setName("jLdataIniInscripcio"); // NOI18N

        jLDataRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLDataRealitzacio.setText("Data Inici Inscripció");
        jLDataRealitzacio.setName("jLDataRealitzacio"); // NOI18N

        jLdataIniRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLdataIniRealitzacio.setText("Data Inici Inscripció");
        jLdataIniRealitzacio.setName("jLdataIniRealitzacio"); // NOI18N

        jTIniRealitzacio.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTIniRealitzacio.setName("jTIniRealitzacio"); // NOI18N

        jLDataFiRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLDataFiRealitzacio.setText("Data Inici Inscripció");
        jLDataFiRealitzacio.setName("jLDataFiRealitzacio"); // NOI18N

        jTFiRealitzacio.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTFiRealitzacio.setName("jTFiRealitzacio"); // NOI18N

        javax.swing.GroupLayout jPanelInscripcioLayout = new javax.swing.GroupLayout(jPanelInscripcio);
        jPanelInscripcio.setLayout(jPanelInscripcioLayout);
        jPanelInscripcioLayout.setHorizontalGroup(
            jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInscripcioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLDataRealitzacio, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jLDataInscripcio, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 73, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                .addGroup(jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelInscripcioLayout.createSequentialGroup()
                        .addComponent(jLdataIniInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTIniInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLdataFiInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTFiInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelInscripcioLayout.createSequentialGroup()
                        .addComponent(jLdataIniRealitzacio, 0, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTIniRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLDataFiRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelInscripcioLayout.setVerticalGroup(
            jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInscripcioLayout.createSequentialGroup()
                .addGroup(jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLDataInscripcio)
                    .addComponent(jTFiInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLdataFiInscripcio)
                    .addComponent(jTIniInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLdataIniInscripcio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInscripcioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLDataRealitzacio)
                    .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLDataFiRealitzacio)
                    .addComponent(jTIniRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLdataIniRealitzacio))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanelBotons.setName("jPanelBotons"); // NOI18N

        jBBuscar.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoFiltrar.png"))); // NOI18N
        jBBuscar.setText("Filtrar");
        jBBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBBuscar.setMaximumSize(new java.awt.Dimension(60, 60));
        jBBuscar.setMinimumSize(new java.awt.Dimension(60, 60));
        jBBuscar.setName("jBBuscar"); // NOI18N
        jBBuscar.setPreferredSize(new java.awt.Dimension(60, 60));
        jBBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBBuscarActionPerformed(evt);
            }
        });

        jBVeure.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBVeure.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoModificar.png"))); // NOI18N
        jBVeure.setText("Veure");
        jBVeure.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBVeure.setMaximumSize(new java.awt.Dimension(60, 60));
        jBVeure.setMinimumSize(new java.awt.Dimension(60, 60));
        jBVeure.setName("jBVeure"); // NOI18N
        jBVeure.setPreferredSize(new java.awt.Dimension(60, 60));
        jBVeure.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBVeure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBVeureActionPerformed(evt);
            }
        });

        jBSortir.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBSortir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoSortir.png"))); // NOI18N
        jBSortir.setText("Sortir");
        jBSortir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBSortir.setMaximumSize(new java.awt.Dimension(60, 60));
        jBSortir.setMinimumSize(new java.awt.Dimension(60, 60));
        jBSortir.setName("jBSortir"); // NOI18N
        jBSortir.setPreferredSize(new java.awt.Dimension(60, 60));
        jBSortir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBSortir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSortirActionPerformed(evt);
            }
        });

        jBNovaProva.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBNovaProva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoNou.png"))); // NOI18N
        jBNovaProva.setText("Cercar");
        jBNovaProva.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBNovaProva.setMaximumSize(new java.awt.Dimension(60, 60));
        jBNovaProva.setMinimumSize(new java.awt.Dimension(60, 60));
        jBNovaProva.setName("jBNovaProva"); // NOI18N
        jBNovaProva.setPreferredSize(new java.awt.Dimension(60, 60));
        jBNovaProva.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBNovaProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNovaProvaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBotonsLayout = new javax.swing.GroupLayout(jPanelBotons);
        jPanelBotons.setLayout(jPanelBotonsLayout);
        jPanelBotonsLayout.setHorizontalGroup(
            jPanelBotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBNovaProva, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53)
                .addComponent(jBBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBVeure, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 214, Short.MAX_VALUE)
                .addComponent(jBSortir, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelBotonsLayout.setVerticalGroup(
            jPanelBotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelBotonsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jBNovaProva, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(jBBuscar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(jBVeure, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(jBSortir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                .addGap(29, 29, 29))
        );

        jPanelFiltre.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.panelprovafiltrada")));
        jPanelFiltre.setName("jPanelFiltre"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTaulaProves.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Identificador", "Descripció"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTaulaProves.setName("jTaulaProves"); // NOI18N
        jTaulaProves.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTaulaProvesMousePressed(evt);
            }
        });
        jTaulaProves.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jTaulaProvesAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jScrollPane1.setViewportView(jTaulaProves);

        javax.swing.GroupLayout jPanelFiltreLayout = new javax.swing.GroupLayout(jPanelFiltre);
        jPanelFiltre.setLayout(jPanelFiltreLayout);
        jPanelFiltreLayout.setHorizontalGroup(
            jPanelFiltreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
        );
        jPanelFiltreLayout.setVerticalGroup(
            jPanelFiltreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFiltreLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanellMenu.setName("jPanellMenu"); // NOI18N

        jMenuEdicio.setText("Arxiu");
        jMenuEdicio.setName("jMenuEdicio"); // NOI18N

        jMenuItemSortir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemSortir.setText("jMenuItem1");
        jMenuItemSortir.setName("jMenuItemSortir"); // NOI18N
        jMenuItemSortir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSortirActionPerformed(evt);
            }
        });
        jMenuEdicio.add(jMenuItemSortir);

        jPanellMenu.add(jMenuEdicio);

        jMenuArxiu.setText("Edició");
        jMenuArxiu.setName("jMenuArxiu"); // NOI18N

        jMenuItemNova.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemNova.setText("jMenuItem1");
        jMenuItemNova.setName("jMenuItemNova"); // NOI18N
        jMenuItemNova.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemNovaActionPerformed(evt);
            }
        });
        jMenuArxiu.add(jMenuItemNova);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jMenuArxiu.add(jSeparator2);

        jMenuItemBuscar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemBuscar.setText("jMenuItem1");
        jMenuItemBuscar.setName("jMenuItemBuscar"); // NOI18N
        jMenuItemBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemBuscarActionPerformed(evt);
            }
        });
        jMenuArxiu.add(jMenuItemBuscar);

        jMenuItemVeure.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemVeure.setText("jMenuItem1");
        jMenuItemVeure.setName("jMenuItemVeure"); // NOI18N
        jMenuItemVeure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemVeureActionPerformed(evt);
            }
        });
        jMenuArxiu.add(jMenuItemVeure);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jMenuArxiu.add(jSeparator1);

        jPanellMenu.add(jMenuArxiu);

        setJMenuBar(jPanellMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanelFiltre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelInscripcio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelBotons, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelProva, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(29, 29, 29))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelBotons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelProva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelFiltre, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Acció que realitza el filtratge de les proves<br>
     * En funció dels paràmetres entrats a la pantalla 
     * @param evt               disparador
     */
    private void jBBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBBuscarActionPerformed
       
           proves=new ArrayList<Prova>();
            try {
                if(!jTIdProva.getText().equals("")){
                 Prova prova= remotProves.getProva(Integer.parseInt(jTIdProva.getText()));
                 if (prova!=null) 
                     proves.add(prova);                 
                }else{
                   System.out.println("buscarproves"); 
                    proves=remotProves.getProves(jTDescripcio.getText(), jTIniInscripcio.getText(), jTFiInscripcio.getText(), 
                        jTIniRealitzacio.getText(), jTFiRealitzacio.getText());
                }
                jTaulaProves.setModel(carregarTaula(proves));
               
                TableColumnModel modelColumna = jTaulaProves.getColumnModel();         
                modelColumna.getColumn(1).setPreferredWidth(400);

                
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
            }    
    }//GEN-LAST:event_jBBuscarActionPerformed
    /**
     * Acció que ocurreix al tancar la finestra <br>
     * Descarrega tots els recursos
     * @param evt               Disparador
     */
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        this.dispose();               
    }//GEN-LAST:event_formWindowClosed
    /**
     * Acció que ocurreix al apretar el botó Sortir<br>
     * Descarrega tots els recursos
     * @param evt               Disparador
     */
    private void jBSortirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSortirActionPerformed
        this.dispose();
        
    }//GEN-LAST:event_jBSortirActionPerformed
    /**
     * Acció que passa quan s'afegeix un nou element a taula on es presenten les proves <br>
     * Deshabilita el botó veure prova i descarrega la provaSeleccionada en aquell moment
     * @param evt               Disparador
     */
    private void jTaulaProvesAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jTaulaProvesAncestorAdded
         jBVeure.setEnabled(false);
         jMenuItemVeure.setEnabled(false);
         provaSeleccionada=null;
    }//GEN-LAST:event_jTaulaProvesAncestorAdded
    /**
     * Acció que passa quan es clica el botó veure prova <br>
     * Accedeix a la pantalla manteniment de proves, i li passa com a paràmetre<br>
     * La prova seleccinada, a part del remot per la connexió i l'usuari actual
     * @param evt           
     */
    private void jBVeureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBVeureActionPerformed
        try {
            
            if(EOlympicsUtils.validarOberturaProva(provaSeleccionada)){
                PanelMantenimentGestioProves panelProva= new PanelMantenimentGestioProves(provaSeleccionada,remotProves,usuari);
                panelProva.setLocationRelativeTo(null);
                panelProva.setVisible(true);
                this.dispose();
            }

        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("ERR_DATE"), "ERR DATE", JOptionPane.ERROR_MESSAGE);                                
        }
    }//GEN-LAST:event_jBVeureActionPerformed
    /**
     * Acció que passa al clicar el botó nova prova<br>
     * Accedeix a la pantalla manteniment de proves, i li passa com a paràmetre<br>
     * Una nova prova,  a part del remot per la connexió i l'usuari actual
     * @param evt           Disparador
     */
    private void jBNovaProvaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNovaProvaActionPerformed
        provaSeleccionada=new Prova(-1,"");
        provaSeleccionada.setEstat(EstatProva.INICIAL);
        try {
            PanelMantenimentGestioProves panelProva= new PanelMantenimentGestioProves(provaSeleccionada,remotProves,usuari);
            panelProva.setLocationRelativeTo(null);
            panelProva.setVisible(true);
            this.dispose();
        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("ERR_DATE"), "ERR DATE", JOptionPane.ERROR_MESSAGE);                                
        }       
    }//GEN-LAST:event_jBNovaProvaActionPerformed
    /**
     * Acció que passa al clicar sobre la taula de proves filtrades<br>
     * Agafa la prova seleccionada
     * 
     * @param evt           Disparador
     */
    private void jTaulaProvesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTaulaProvesMousePressed
        if(jTaulaProves.getSelectedRow()>=0){
            jBVeure.setEnabled(true);
            jMenuItemVeure.setEnabled(true);
            try {
                provaSeleccionada=remotProves.getProva((Integer)(jTaulaProves.getModel().getValueAt(jTaulaProves.getSelectedRow(),0)));
            } catch (RemoteException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR REMOT", JOptionPane.ERROR_MESSAGE);                                
            } catch (EOlympicsException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR SQL", JOptionPane.ERROR_MESSAGE);                                
            }
        }
        else{
            jBVeure.setEnabled(false);
            jMenuItemVeure.setEnabled(false);
            provaSeleccionada=null;
        }
    }//GEN-LAST:event_jTaulaProvesMousePressed
    /**
     * Accio que passa al clicar sobre el menu nova prova<br>
     * Crea una nova prova i accedeix a la pantalla manteniment de proves
     * @param evt               Disparador
     */
    private void jMenuItemNovaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNovaActionPerformed
        jBNovaProvaActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemNovaActionPerformed
    /**
     * Accio que passa al clicar sobre el menu Filtrar prova<br>
     * Cerca les proves amb el filtre definit en els camps
     * @param evt               Disparador
     */
    private void jMenuItemBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemBuscarActionPerformed
        jBBuscarActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemBuscarActionPerformed
     /**
     * Accio que passa al clicar sobre el menu veure prova<br>
     * Accedeix a la pantalla manteniment de proves amb la prova seleccionada
     * @param evt               Disparador
     */
    private void jMenuItemVeureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemVeureActionPerformed
        jBVeureActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemVeureActionPerformed
    /**
     * Acció que passa al clicar sobre el menu Sortir<br>
     * Descarrega els recursos de la pantalla
     * @param evt           Disparador
     */
    private void jMenuItemSortirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSortirActionPerformed
        jBSortirActionPerformed(evt);
    }//GEN-LAST:event_jMenuItemSortirActionPerformed
    /**
     * Acció que personalitza les etiquetes de la pantalla
     */
    private void pintarEtiquetes(){        
         this.setTitle(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settitol"));         
         jLDataFiRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.datafirealitzacio"));
         jLDataInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.datainscripcio"));
         jLDataRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.datarealitzacio"));
         jLDescripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.descripcio"));
         
         jLIdProva.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.idprova"));
         jLProva.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.prova"));
         jLdataFiInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.datafi"));
         jLdataIniInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.dataini"));
         jLdataIniRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.dataini")); 
         jLDataFiRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.datafi"));
         
         jBBuscar.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.tooltip.buscar"));
         jBVeure.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.tooltip.veure"));
         jBSortir.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.tooltip.sortir"));
         jBNovaProva.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.tooltip.novaprova"));
    
         jBBuscar.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.buscar"));
         jBVeure.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.veure"));
         jBSortir.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.sortir"));
         jBNovaProva.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.novaprova"));
         
         jMenuEdicio.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.edicio"));
        jMenuArxiu.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.arxiu"));
        jMenuItemNova.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.itemnova"));        
        jMenuItemBuscar.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.itemfiltrar"));
        jMenuItemSortir.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.itemsortir"));
        jMenuItemVeure.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.menu.itemveure"));         
    }
    /**
     * Carrega el model que farà servir la taula de proves
     * @param proves
     * @return DefaultTableModel        dades de les proves
     */
    private DefaultTableModel carregarTaula(List<Prova> proves){
        String [] columnes={"ID PROVA","DESCRIPCIO"};        
        Object[][] dades=new Object[proves.size()][2];                          
        Integer i=0;
        DefaultTableModel dadesTaula;
          for(Prova p:proves){
            dades[i][0]=p.getIdProva();
            dades[i][1]=p.getDescripcio();
            i++;
        }        
        dadesTaula=new DefaultTableModel(dades,columnes)
                 {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
            
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        
        return dadesTaula;        
    }    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBBuscar;
    private javax.swing.JButton jBNovaProva;
    private javax.swing.JButton jBSortir;
    private javax.swing.JButton jBVeure;
    private javax.swing.JLabel jLDataFiRealitzacio;
    private javax.swing.JLabel jLDataInscripcio;
    private javax.swing.JLabel jLDataRealitzacio;
    private javax.swing.JLabel jLDescripcio;
    private javax.swing.JLabel jLIdProva;
    private javax.swing.JLabel jLProva;
    private javax.swing.JLabel jLdataFiInscripcio;
    private javax.swing.JLabel jLdataIniInscripcio;
    private javax.swing.JLabel jLdataIniRealitzacio;
    private javax.swing.JMenu jMenuArxiu;
    private javax.swing.JMenu jMenuEdicio;
    private javax.swing.JMenuItem jMenuItemBuscar;
    private javax.swing.JMenuItem jMenuItemNova;
    private javax.swing.JMenuItem jMenuItemSortir;
    private javax.swing.JMenuItem jMenuItemVeure;
    private javax.swing.JPanel jPanelBotons;
    private javax.swing.JPanel jPanelFiltre;
    private javax.swing.JPanel jPanelInscripcio;
    private javax.swing.JPanel jPanelProva;
    private javax.swing.JMenuBar jPanellMenu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JTextField jTDescripcio;
    private javax.swing.JTextField jTFiInscripcio;
    private javax.swing.JTextField jTFiRealitzacio;
    private javax.swing.JTextField jTIdProva;
    private javax.swing.JTextField jTIniInscripcio;
    private javax.swing.JTextField jTIniRealitzacio;
    private javax.swing.JTable jTaulaProves;
    // End of variables declaration//GEN-END:variables
}
